// pages/mys/index.js
const app = getApp(); // 获取应用实例

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 用户信息
    uname: '用户昵称',
    uhead: '/imgs/bai.png',
    udesc: '已使用100天',
    scan_total: 0,
    follow_total: 0,
    reply_total: 0,
    scene_total: 0,
    fuwu_total: 0,
    ad_total: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userInfo = wx.getStorageSync('userInfo');
    if (!userInfo || userInfo == '') {
        wx.navigateTo({
          url: '/pages/index/login/index',
        }); return
    }
    this.setData({
        uname: userInfo.nickName,
        uhead: userInfo.avatarUrl,
    });
    this.tongji();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 获取统计
  tongji: function (e) {
    var that = this;
    var userInfo = wx.getStorageSync('userInfo');
    var formData = {
      uid: userInfo.uid,
    };
    wx.request({
      method: 'POST',
      url: app.globalData.domainXcx + '/my/index',
      data: formData,
      timeout: 10000, //接口超时10S
      success: function (res) {
          res = res.data;
          console.log(res);
          if (res.code!=0) {
            wx.showToast({
              title: res.msg, icon: 'none'
            }); r
            eturn
          }
          var d = res.data;
          that.setData({
            uname: d.uname,
            uhead: d.uhead,
            udesc: d.udesc,
            scan_total: d.scan_total,
            follow_total: d.follow_total,
            reply_total: d.reply_total,
            scene_total: d.scene_total,
            fuwu_total: d.fuwu_total,
            ad_total: d.ad_total,
          });
      },
      fail: function () {
          console.log('网络错误');
      }
    });  
  },

  // 我扫码的
  toScan: function (e) {
    wx.navigateTo({
      url: '/pages/mys/scan/index',
    }); return
  },

  // 我关注的
  toFollow: function (e) {
    wx.navigateTo({
      url: '/pages/mys/follow/index',
    }); return
  },

  // 我回复的
  toReply: function (e) {
    wx.navigateTo({
      url: '/pages/mys/reply/index',
    }); return
  },

  // 场景帮助
  toScene: function (e) {
    wx.navigateTo({
      url: '/pages/mys/scene/index',
    }); return
  },

  // 去登录
  tologin: function (e) {
    wx.navigateTo({
      url: '/pages/index/login/index',
    }); return
  },

  // 去服务
  toFuwu: function (e) {
    wx.navigateTo({
      url: '/pages/mys/fuwu/index?viewFlag=all',
    }); return
  },

  // 去推广
  toAd: function (e) {
    wx.navigateTo({
      url: '/pages/mys/ad/index',
    }); return
  },
});